home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVIPS_55 / dvips / src / c / makefont < prev    next >
Text File  |  1994-05-06  |  8KB  |  296 lines

  1. /*
  2.  *   This software is Copyright 1988 by Radical Eye Software.
  3.  */
  4. #include "dvips.h"
  5. extern int quiet ;
  6. extern int filter ;
  7. extern int dontmakefont ;
  8. extern int system() ;
  9. extern Boolean secure ;
  10. extern char *getenv(), *newstring() ;
  11. extern char *mfmode ;
  12. #ifdef OS2
  13. #include <stdlib.h>
  14. #endif
  15. #if defined MSDOS || defined OS2
  16. extern char *mfjobname ;
  17. extern FILE *mfjobfile ;
  18. extern char *pkpath ;
  19. extern int actualdpi ;
  20. extern int vactualdpi ;
  21. /*
  22.  *  Write mfjob file
  23.  */
  24. void
  25. mfjobout(font,mag)
  26. char *font;
  27. double mag;
  28. {
  29.    if (mfjobfile == (FILE *)NULL) {
  30.       char pkout[128];
  31.       char *p;
  32.       int i;
  33.       for (p=pkpath, i=0; *p && *p!=PATHSEP && i<127; p++) {
  34.          if (*p=='%') {
  35.             p++;
  36.             switch(*p) { /* convert %x codes to mfjob @y codes */
  37.                case 'b':
  38.                   sprintf(pkout+i,"%d",actualdpi);
  39.                   break;
  40.                case 'd':
  41.                   strcpy(pkout+i,"@Rr");
  42.                   break;
  43.                case 'f':
  44.                   strcpy(pkout+i,"@f");
  45.                   break;
  46.                case 'p':
  47.                   strcpy(pkout+i,"pk");
  48.                   break;
  49.                case 'm':
  50.                   strcpy(pkout+i,mfmode);
  51.                   break;
  52.                case '%':
  53.                   strcpy(pkout+i,"%");
  54.                   break;
  55.                default:
  56.                   sprintf(pkout+i, "%%%c", *p) ;
  57.                   fprintf(stderr,"Unknown option %%%c in pk path\n",*p);
  58.             }
  59.             i += strlen(pkout+i);
  60.          }
  61.          else
  62.            pkout[i++] = *p;
  63.       }
  64.       *p='\0'; /* Could some DOS person explain to me what this does? */
  65.       pkout[i] = 0 ;
  66.       mfjobfile =  fopen(mfjobname,"w");
  67.       if (mfjobfile == (FILE *)NULL)
  68.          return;
  69.       fprintf(mfjobfile,"input[dvidrv];\n{\ndriver=dvips;\n");
  70.       if (actualdpi == vactualdpi)
  71.          fprintf(mfjobfile,"mode=%s[%d];\n",mfmode,actualdpi);
  72.       else
  73.          fprintf(mfjobfile,"mode=%s[%d %d];\n",mfmode,actualdpi,vactualdpi);
  74.       fprintf(mfjobfile,"output=pk[%s];\n",pkout);
  75.    }
  76.    fprintf(mfjobfile,"{font=%s; mag=%f;}\n",font,mag);
  77.    (void)fprintf(stderr,
  78.         "Appending {font=%s; mag=%f;} to %s\n",font,mag,mfjobname) ;
  79. }
  80. #endif
  81. /*
  82.  *   Calculate magstep values.
  83.  */
  84. static int
  85. magstep(n, bdpi)
  86. register int n, bdpi ;
  87. {
  88.    register float t ;
  89.    int neg = 0 ;
  90.  
  91.    if (n < 0) {
  92.       neg = 1 ;
  93.       n = -n ;
  94.    }
  95.    if (n & 1) {
  96.       n &= ~1 ;
  97.       t = 1.095445115 ;
  98.    } else
  99.       t = 1.0 ;
  100.    while (n > 8) {
  101.       n -= 8 ;
  102.       t = t * 2.0736 ;
  103.    }
  104.    while (n > 0) {
  105.       n -= 2 ;
  106.       t = t * 1.2 ;
  107.    }
  108.    if (neg)
  109.       return((int)(0.5 + bdpi / t)) ;
  110.    else
  111.       return((int)(0.5 + bdpi * t)) ;
  112. }
  113. #ifdef MAKEPKCMD
  114. static char *defcommand = MAKEPKCMD " %n %d %b %m" ;
  115. #else
  116. #ifdef OS2
  117. static char *doscommand = "command /c MakeTeXP %n %d %b %m" ;
  118. static char *os2command = "MakeTeXP %n %d %b %m" ;
  119. #define defcommand ( _osmode==OS2_MODE ? os2command : doscommand )
  120. #else
  121. #ifdef MSDOS
  122. static char *defcommand = "command /c MakeTeXP %n %d %b %m" ;
  123. #else
  124. #ifdef VMCMS
  125. static char *defcommand = "EXEC MakeTeXPK %n %d %b %m" ;
  126. #else
  127. static char *defcommand = "MakeTeXPK %n %d %b %m" ;
  128. #endif
  129. #endif
  130. #endif
  131. #endif
  132. char *command = 0 ;
  133. /*
  134.  *   This routine tries to create a font by executing a command, and
  135.  *   then opening the font again if possible.
  136.  */
  137. static char buf[125] ;
  138. void
  139. makefont(name, dpi, bdpi)
  140.    char *name ;
  141.    int dpi, bdpi ;
  142. {
  143.    register char *p, *q ;
  144.    register int m, n ;
  145. #if defined MSDOS || defined OS2
  146.    double t;
  147. #endif
  148.  
  149.    if (command == 0)
  150.       if (secure == 0 && (command=getenv("MAKETEXPK")))
  151.          command = newstring(command) ;
  152.       else 
  153.          command = defcommand ;
  154.    for (p=command, q=buf; *p; p++)
  155.       if (*p != '%')
  156.          *q++ = *p ;
  157.       else {
  158.          switch (*++p) {
  159. case 'n' : case 'N' :
  160.             (void)strcpy(q, name) ;
  161.             break ;
  162. case 'd' : case 'D' :
  163.             (void)sprintf(q, "%d", dpi) ;
  164.             break ;
  165. case 'b' : case 'B' :
  166.             (void)sprintf(q, "%d", bdpi) ;
  167.             break ;
  168. case 'm' : case 'M' :
  169. /*
  170.  *   Here we want to return a string.  If we can find some integer
  171.  *   m such that floor(0.5 + bdpi * 1.2 ^ (m/2)) = dpi, we write out
  172.  *      magstep(m/2)
  173.  *   where m/2 is a decimal number; else we write out
  174.  *      dpi/bdpi
  175.  *   We do this for the very slight improvement in accuracy that
  176.  *   magstep() gives us over the rounded dpi/bdpi.
  177.  */
  178.             m = 0 ;
  179.             if (dpi < bdpi) {
  180.                while (1) {
  181.                   m-- ;
  182.                   n = magstep(m, bdpi) ;
  183.                   if (n == dpi)
  184.                      break ;
  185.                   if (n < dpi || m < -40) {
  186.                      m = 9999 ;
  187.                      break ;
  188.                   }
  189.                }
  190.             } else if (dpi > bdpi) {
  191.                while (1) {
  192.                   m++ ;
  193.                   n = magstep(m, bdpi) ;
  194.                   if (n == dpi)
  195.                      break ;
  196.                   if (n > dpi || m > 40) {
  197.                      m = 9999 ;
  198.                      break ;
  199.                   }
  200.                }
  201.             }
  202. #if defined MSDOS || defined OS2
  203. /* write out magnification as decimal number */
  204.             if (m == 9999) {
  205.                t = (double)dpi/bdpi;
  206.             } else {
  207.                if (m < 0)
  208.                     n = -m;
  209.                else
  210.                     n = m;
  211.                if (n & 1) {
  212.                     n &= ~1 ;
  213.                     t = 1.095445115 ;
  214.                } else
  215.                     t = 1.0 ;
  216.                while (n > 0) {
  217.                     n -= 2 ;
  218.                     t = t * 1.2 ;
  219.                }
  220.                if (m < 0)
  221.                     t = 1 / t ;
  222.             }
  223.             (void)sprintf(q, "%12.9f", t) ;
  224. #else
  225.             if (m == 9999) {
  226.                (void)sprintf(q, "%d+%d/%d", dpi/bdpi, dpi%bdpi, bdpi) ;
  227.             } else if (m >= 0) {
  228.                (void)sprintf(q, "magstep\\(%d.%d\\)", m/2, (m&1)*5) ;
  229.             } else {
  230.                (void)sprintf(q, "magstep\\(-%d.%d\\)", (-m)/2, (m&1)*5) ;
  231.             }
  232. #endif
  233.             break ;
  234. case 0 :    *q = 0 ;
  235.             break ;
  236. default:    *q++ = *p ;
  237.             *q = 0 ;
  238.             break ;
  239.          }
  240.          q += strlen(q) ;
  241.       }
  242.    *q = 0 ;
  243.    if (mfmode) {
  244.       strcpy(q, " ") ;
  245.       strcat(q, mfmode) ;
  246.    }
  247. #ifdef OS2
  248.    if ((_osmode == OS2_MODE) && filter)
  249.       (void)strcat(buf, quiet ? " >nul" : " 1>&2") ;
  250. #else
  251. #ifndef VMCMS   /* no filters and no need to print to stderr */
  252. #ifndef MVSXA
  253. #ifndef MSDOS
  254.    if (filter)
  255.       (void)strcat(buf, quiet ? " >/dev/null" : " 1>&2") ;
  256. #endif
  257. #endif
  258. #endif
  259. #endif
  260.  
  261. #if defined MSDOS || defined OS2
  262.    if (! quiet && mfjobname == (char *)NULL)
  263.       (void)fprintf(stderr, "- %s\n", buf) ;
  264.    if (dontmakefont == 0) {
  265.       if (mfjobname != (char *)NULL)
  266.          mfjobout(name,t);
  267.       else
  268.          (void)system(buf) ;
  269.    }
  270. #else
  271.    if (! quiet)
  272.       (void)fprintf(stderr, "- %s\n", buf) ;
  273.    if (dontmakefont == 0)
  274.       (void)system(buf) ;
  275. #endif
  276.    else {
  277.       static FILE *fontlog = 0 ;
  278.  
  279.       if (fontlog == 0) {
  280.          fontlog = fopen("missfont.log", "a") ;
  281.          if (fontlog != 0) {
  282.             (void)fprintf(stderr,
  283. #ifndef VMCMS
  284.                   "Appending font creation commands to missfont.log\n") ;
  285. #else
  286.   "\nMissing font data will be passed to DVIPS EXEC via MISSFONT LOG\n");
  287. #endif
  288.          }
  289.       }
  290.       if (fontlog != 0) {
  291.          (void)fprintf(fontlog, "%s\n", buf) ;
  292.          (void)fflush(fontlog) ;
  293.       }
  294.    }
  295. }
  296.